unit uZhuyuanDataForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
  TZhuyuanDataForm = class(TForm)
    pnlBottom: TPanel;
    btnCancel: TButton;
    btnOK: TButton;
    pnlTop: TPanel;
    rbLastMonth: TRadioButton;
    rbLastWeek: TRadioButton;
    rbYesterday: TRadioButton;
    rbThisMonth: TRadioButton;
    rbThisWeek: TRadioButton;
    pnlCenter: TPanel;
    lbl1: TLabel;
    lbl2: TLabel;
    dtpLastSyncTime: TDateTimePicker;
    chkLastSyncTime: TCheckBox;
    dtpCyTime: TDateTimePicker;
    rbDefault: TRadioButton;
    procedure chkLastSyncTimeClick(Sender: TObject);
    procedure FixTypeRadioClick(Sender: TObject);
    procedure dtpLastSyncTimeChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    LastSyncTime: TDateTime;
  end;

var
  ZhuyuanDataForm: TZhuyuanDataForm;

implementation

uses DateUtils;

{$R *.dfm}

procedure TZhuyuanDataForm.chkLastSyncTimeClick(Sender: TObject);
begin
  dtpLastSyncTime.Enabled := chkLastSyncTime.Checked;
end;

procedure TZhuyuanDataForm.FixTypeRadioClick(Sender: TObject);
var
  year, month: Word;
  CurrTime: TDateTime;
begin
  CurrTime := Now;
  month := MonthOf(CurrTime);
  year := YearOf(CurrTime);
  case TRadioButton(Sender).Tag of
    0:
    begin
      dtpLastSyncTime.DateTime := LastSyncTime;
      dtpCyTime.DateTime := Yesterday;
    end;
    1:
    begin
      if month = 1 then
      begin
        year := year - 1;
        month := 13;
      end;
      dtpLastSyncTime.DateTime := StartOfAMonth(year, month - 1);
      dtpCyTime.DateTime := EndOfAMonth(year, month - 1);
    end;
    2:
    begin
      dtpLastSyncTime.DateTime := StartOfTheMonth(CurrTime);
      dtpCyTime.DateTime := EndOfTheMonth(CurrTime);
    end;
    3:
    begin
      dtpLastSyncTime.DateTime := StartOfTheWeek(CurrTime - 7);
      dtpCyTime.DateTime := EndOfTheWeek(CurrTime - 7);
    end;
    4:
    begin
      dtpLastSyncTime.DateTime := StartOfTheWeek(CurrTime);
      dtpCyTime.DateTime := EndOfTheWeek(CurrTime);
    end;
    5:
    begin
      dtpLastSyncTime.DateTime := Yesterday;
      dtpCyTime.DateTime := Yesterday;
    end;
  end;
end;

procedure TZhuyuanDataForm.dtpLastSyncTimeChange(Sender: TObject);
begin
  dtpCyTime.DateTime := EndOfTheMonth(dtpLastSyncTime.DateTime);
end;

end.
